package com.yonyou.pmclouds.basecom.bp.processor;

import com.yonyou.pmclouds.basecom.entity.SuperVO;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.util.BeanHelper;
import com.yonyou.pmclouds.basecom.util.CommonFieldConst;
import com.yonyou.pmclouds.project.entity.ProjectConst;
import com.yonyou.pmclouds.project.entity.ProjectVO;
import com.yonyou.pmclouds.project.rmiitf.ProjectSimpleQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ProjectStatusCheckProcessor<T extends SuperVO> implements SingleProcessor<T> {

    @Autowired
    private ProjectSimpleQuery projectSimpleQuery;

    @Override
    public void process(T vo, T orig) throws BusinessException {

        String pk_project = BeanHelper.getProperty(vo, CommonFieldConst.PK_PROJECT) == null ?
                (String)BeanHelper.getProperty(vo, CommonFieldConst.PKPROJECT):
                (String)BeanHelper.getProperty(vo, CommonFieldConst.PK_PROJECT);

        ProjectVO projectVO = projectSimpleQuery.queryProject(pk_project);

        if(projectVO.getProjectState() == ProjectConst.STATE_END)
            throw new BusinessException("项目已结束，不能再发生业务");

    }
}
